package testPaperWrongHistory.jsonWrongHistory;

import android.util.Log;

import com.example.lancooznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import lancooUpLoad.DataPackage;
import lancooUpLoad.PaperInfor;
import testPaperWrongHistory.HistoryWrongQuesPaperActivity;

/**
 * Created by Administrator on 2017/8/29/029.
 */

public class HistoryWrongQuesPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;

    public HistoryWrongQuesPresenter(ILoadPaperView view) {
        this.view =  view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();
        HttpOnNextListener<List<HistoryWrongQuesJson>> httpOnNextListener = new HttpOnNextListener<List<HistoryWrongQuesJson>>() {

            @Override
            public void onNext(List<HistoryWrongQuesJson> wrongQuesHistoryJson) {
                int totalCount = wrongQuesHistoryJson.size();
                Log.e("====totalCount====","==="+totalCount);
                if(totalCount>0){
                    view.hideLoading();
                    view.loadData(wrongQuesHistoryJson);
                }else {
                    view.showNoData("暂无历史推荐题");
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }
        };
        HistoryWrongQuesParam api = new HistoryWrongQuesParam(httpOnNextListener, (HistoryWrongQuesPaperActivity)view);

        api.setWrongQuesParams(DataPackage.GetWrongQuesParams(UserInfo.StuId,UserInfo.SubjectId,UserInfo.StageNo,UserInfo.PaperFrom,
                PaperInfor.QuesID));
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }

}